<template>
	<div>
		<cus-modal ref="auditModal" :center="true" :title="auditDish.dishName + '审核意见'" :showOtherBtn="true"
			otherBtnType="error" :showCancelBtn="false" @on-visible-change="onVisibleChange">
			<div :style="{ height: auditdata.length > 0 ? '190px' : '' }" style="overflow-y: auto; overflow-x: hidden">
				<div class="mb_10" v-for="(item, index) in auditdata" :key="index">
					<div class="fl mb_10">
						<div>{{ `${index + 1}、${item.gmtCreate}` }}</div>
						<div class="text ml_24">{{ item.applyComment }}</div>
					</div>
					<div>
						<p class="ml_10" style="padding: 0 10px 0 0">
							{{ item.auditComment ? item.auditComment : '暂无!' }}
						</p>
					</div>
				</div>
			</div>
			<div>
				<Input v-model="auditDish.personalizedFailReason" type="textarea" maxlength="100" show-word-limit
					:autosize="{ minRows: 5, maxRows: 10 }" placeholder="请输入审核意见"></Input>
			</div>
			<div slot="footer">
				<slot name="footer">
					<div class="modal-footer">
						<cus-button size="small" type="error" class="mr_2" @onClick="onReject()">驳回</cus-button>
						<cus-button type="success" size="small" @onClick="onOk()">通过</cus-button>

					</div>
				</slot>
			</div>
			<Spin size="large" fix v-if="loading"></Spin>
		</cus-modal>
	</div>
</template>

<script>
import {
	getCookbookLog,
	verifyPersonalizedDish,
} from '@/api/organ/dishesModule'
export default {
	name: 'recipeModal',
	data() {
		return {
			loading: false,
			auditComment: '',
			auditDish: {
				dishName: '', //菜肴名称
				dishCode: '', //个性化菜肴编码
				personalizedFailReason: '', //个性化菜肴未通过原因
				personalizedStatus: '',  //个性化菜肴状态
			},
			auditdata: []
		}
	},
	mounted() { },
	methods: {
		// 审核日志-----------------------接口
		getCookbookLog() {
			this.loading = true
			return new Promise((resolve) => {
				getCookbookLog({ mealPlanId: this.form.mealPlanId }).then((res) => {
					this.loading = false
					if (res.code === 1) {
						this.data = res.data
						resolve()
					}
				})
			})
		},
		onVisibleChange(v) {
			if (!v) {
				this.auditComment = '';
			}
		},
		show(row) {
			// this.loading = false
			let {
				dishName,
				dishCode
			} = row
			console.log(dishName);
			this.auditDish.dishCode = dishCode
			this.auditDish.dishName = dishName
			this.$refs["auditModal"].show = true;
			// this.getCookbookLog()
		},
		onOk() {
			this.auditDish.personalizedStatus = 1
			this.verifyPersonalizedDish()
		},
		onReject() {
			this.auditDish.personalizedStatus = 2
			this.verifyPersonalizedDish()
		},
		onCancel() {
			let params = new Object()
			params.auditComment = this.auditComment
			params.mealPlanId = this.form.mealPlanId
			this.backOutCookbook(params)
		},
		//通过食谱审核
		verifyPersonalizedDish(status) {
			verifyPersonalizedDish(
				this.auditDish
			).then((res) => {
				if (res.code == 1) {
					let msg = this.auditDish.personalizedStatus == 1 ? '菜肴审核成功' : "已将菜肴驳回"
					this.$Message.success(msg)
					this.$refs['auditModal'].show = false
					this.$emit('refetch')
				}
			})
		},
	}
}
</script>

<style scoped lang="less">
.permission {
	/*height: 300px;*/
	width: 500px;
	border: 1px solid #dcdee2;
	overflow-y: auto;
	overflow-x: hidden;
	border-radius: 2px;
	padding: 0 0 0 10px;
}

.permission::-webkit-scrollbar {
	display: none;
}

.fl {
	display: flex;
}

.text {
	font-size: 14px;
	font-family: PingFang SC-Regular, PingFang SC;
	font-weight: 400;
	color: #1e6fff;
}
</style>